package com.itheima.test14;

import com.itheima.test11.Student;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/*
题目四
		请编写main()方法，定义一个字符缓冲输入流BufferedReader对象，读取”test3_4.txt”文件，一次读取一行，将每行数据封装为一个Student对象，并将Student对象存储到一个集合。遍历并打印集合的所有Student信息。
		//定义一个BufferedReader对象
		BufferedReader in = new BufferedReader(......);
		//定义一个集合
		List<Student> stuList = new ArrayList<>();
		//一次读取一行
		......
 */
public class Test14 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("D:\\IdeaProjects\\studentManagerSystem\\homewrok0919\\src\\com\\itheima\\test3_4.txt"));
        ArrayList<Student> stuList = new ArrayList<>();

        String name;
        String gender;
        int age;
        double score;
        String len;
        while ((len = br.readLine()) != null){
//            System.out.println(len);//@测试
            String[] split = len.split(",");
            name = split[0];
            gender = split[1];
            age = Integer.parseInt(split[2]);
            score = Double.parseDouble(split[3]);
//            System.out.println("name=" + name + ",gender=" + gender + ",age=" + age + ",score=" + score);//@测试
            Student stu = new Student(name, gender, age, score);
            stuList.add(stu);
//            System.out.println(stu);//@测试
        }
        br.close();

        for (Student student : stuList) {
            System.out.println(student);
        }
    }
}
